<template>
  <div>
    <my-header :backBtn="true">
			<div slot="title">
			  人脸审核
			</div>
    </my-header>
      <div class="weui-msg">
        <div class="weui-msg__icon-area">
          <i v-if="faceRecord.status===0" class="weui-icon-info weui-icon_msg"></i>
          <i v-if="faceRecord.status===1" class="weui-icon-success weui-icon_msg"></i>
          <i v-if="faceRecord.status===-1||faceRecord.status===-2" class="weui-icon-warn weui-icon_msg"></i>
          <i v-if="faceRecord.status===2" class="weui-icon-waiting weui-icon_msg"></i>
        </div>
        <div class="weui-msg__text-area">
          <h2 class="weui-msg__title">
            <div v-if="faceRecord.status===1">认证成功</div>
            <div v-if="faceRecord.status===-1||faceRecord.status===-2">认证失败</div>
            <div v-if="faceRecord.status===2">认证中</div>
          </h2>
          <div class="weui-msg__desc">
          <div v-if="faceRecord.loginType==='student'">班级：{{faceRecord.gradeName+faceRecord.clazzName}}</div>
          <div>认证人：{{faceRecord.name}}</div>
          <div style="position: relative;top: 0.5rem;font-size: 1.8rem"><a href="javascript:void(0);" @click="previewImage" class="weui-footer__link">查看相片</a></div>
          </div>
        </div>
        <div class="weui-msg__opr-area">
          <div class="weui-btn-area">
            <div v-if="!faceRecord.judge&&loginType==='kindergarten'">
              <a href="javascript:void (0);" @click="passFn" class="weui-btn weui-btn_primary">审核通过</a>
              <a href="javascript:void (0);" @click="killFn" class="weui-btn weui-btn_default">不通过</a>
              <a href="javascript:void (0)" @click="closeWin" class="weui-btn weui-btn_default">关闭</a>
            </div>
            <div v-if="faceRecord.judge">
              <a v-if="faceRecord.status!==1" href="javascript:void (0)" @click="upload" class="weui-btn weui-btn_primary">重新上传</a>
              <a href="javascript:void (0)" @click="closeWin" class="weui-btn weui-btn_default">关闭</a>
            </div>
          </div>
        </div>
      </div>
    <div v-if="dialog.visible">
      <div class="weui-mask"></div>
      <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">{{dialog.title}}</strong></div>
        <div class="weui-dialog__bd">{{dialog.content}}</div>
        <div class="weui-dialog__ft">
          <a href="javascript:void (0);" class="weui-dialog__btn weui-dialog__btn_default" @click="cancelFn">取消</a>
          <a href="javascript:void (0);" class="weui-dialog__btn weui-dialog__btn_primary" @click="subFn">确定</a>
        </div>
      </div>
    </div>
    </div>
</template>

<script>
  import wx from "weixin-js-sdk";
  export default {
    name: "FaceJudge",
    components: {},
    data() {
      return {
        loginType: this.$Cookies.get('loginType'),
        loginId: this.$Cookies.get('loginId'),
        faceRecord: {
          id: '',
          ownId: '',
          name: '',
          judge: false,
          url: '',
          image: '',
          status: 0,
          loginType: '',
          gradeName: '',
          clazzName: '',
          createTime: '',
        },
        dialog:{
          visible:false,
          title:'',
          content:'',
          status:0
        }
      }
    },
    methods: {
      getWxConfig() {
        let url = window.location.href;

        let _this = this;
        _this.$http.fetchWxConfig({url: url}).then(resp => {
          wx.config({
            // debug: true,
            appId: resp.data.appId,
            timestamp: resp.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: resp.data.noncestr, // 必填，生成签名的随机串
            signature: resp.data.sign,// 必填，签名
            jsApiList: ['previewImage'] // 必填，需要使用的JS接口列表
          });
        })
      },
      previewImage() {
        let url=this.faceRecord.url;
        wx.previewImage({
          previewImage: url,
          urls: [url]
        })
      },
      closeWin(){
        wx.closeWindow();
      },
      cancelFn(){
        Object.assign(this.dialog,{
          visible: false,
          title: '',
          content: '',
          status:0
        });
      },
      subFn(){
        let data=Object.assign(this.faceRecord);
        console.log(data);
        data.status=this.dialog.status;
        this.$http.judgeFace(data).then(resp=>{
          this.$router.push('faceManagement')
        })
      },
      passFn(){
        Object.assign(this.dialog,{
          visible: true,
          title: '提示',
          content: '是否审核通过？',
          status:2
        });
      },
      killFn(){
        Object.assign(this.dialog,{
          visible: true,
          title: '警告',
          content: '审核不通过？',
          status:-2
        });
      },
      upload(){
        this.$router.push({
          path:'/photograph',
          query:{
            loginType:this.faceRecord.loginType,
            id:this.faceRecord.ownId
          }
        })
      },
    },
    created() {
      this.faceRecord = this.$route.query;
    },
    mounted() {
      this.getWxConfig();
    }
  }
</script>

<style scoped>

</style>
